home *** CD-ROM | disk | FTP | other *** search
/ BMUG PD-ROM A / PD-ROM A.iso / Programming / Programming Languages / MacOberon / MacOberon (tools) / EditKeys.Tool (.txt) < prev    next >
Encoding:
Oberon Text  |  1991-02-15  |  5.4 KB  |  97 lines  |  [.Ob./.Ob2]

  1. Syntax10.Scn.Fnt
  2. Syntax10i.Scn.Fnt
  3. EditKeys 1.0    cas 10-Aug-90    Keyboard Macros for Ed Editor
  4. You must compile EditKeys first before you can use them.
  5. EditKeys are not linked with the Ed Editor, but added
  6. using Oberon.Call (see below).  If this call returns NIL, Ed just continues
  7. to work without them!
  8.     Compiler.Compile EditKeys.Mod ~
  9. for programmers of macro extensions: Ed.Open KeyCmds.Mod
  10.  * "Copy Out Tool" for using EditKeys.
  11. EditKeys.Definitions 
  12. EditKeys.ReadFiles EditKeys.Text ~
  13. EditKeys.Reset
  14. EditKeys.GetKeyCode
  15. EditKeys.Definitions opens a viewer and lists all current macro definitions.  A selection or a command parameter can be
  16. used to restrict the list to definitions with a certain prefix. EditKeys.ReadFiles takes a list of files and reads in macro
  17. definitions contained therein.  If errors are detected, all definitions are deleted.  Upon module load time, the standard
  18. macro definition file "EditKeys.Text" is read in.  EditKeys.Reset deletes all current macro definitions.  EditKeys.GetKeyCode
  19. helps to find out the codes of certain keys.  Within a text supporting macro keys, entering the hot key causes expansion of the
  20. macro entered to the left.  If no corresponding definition of a macro is found, a second try is made with the standard macro
  21. name "OTHERWISE".
  22.  * Syntax of macro definition files for EditKeys.
  23.         MacroFile = [HotKeyDef] {MacroDef}.
  24.         HotKeyDef = "\" KeyName.    -- sets the macro expansion hot key (default is \)
  25.         MacroDef = MacroName "(" { MacroName | TextStretch | Command} ")".
  26.         MacroName = KeyName | { <arbitrary graphic character except #, (, ), \, ^, and ">  }.
  27.         TextStretch = """ <arbitrary formatted text> """.
  28.         KeyName = "#" <hex number>.
  29.         (Comments and arbitrary white space are allowed between any two terminals. Comments may be nested.)
  30.  * Built-in functions.
  31.         Text stretches are pushed on a parameter stack when processed. Built-in functions may pop parameter(s)
  32.         from that stack.
  33.         ^0    pops a parameter and causes textual insertion.
  34.         ^1    pops a parameter and inserts the corresponding ascii character.
  35.         ^2    pops a parameter which must be a font name; presets the named font.
  36.         ^4    pops a parameter and tries to call it as an Oberon command.
  37.         ^5    keeps the font that would have been used w/o macro; presets this font.
  38.         ^6    picks the font that would have been used w/o macro; forces whole macro to this font.
  39.         ^7    presets the caret position.
  40.         ^8    indents the next line according to the last line's indentation.
  41.         (Parameters are pushed on a stack when processed. Built-in functions pop parameter(s) from that stack.)
  42.  * Remarks.
  43.         When reading in a macro that has been read in before, the new definition replaces the old one.
  44.         Cyclic definitions can be constructed this way; a try to process such a definition is prevented.
  45.         EditKeys and TBoxKeys are compatible in that both support macro files with the same syntax.
  46.         The only difference is that EditKeys does not support changing the offset of characters (^3 in TBoxKeys).
  47.  * Programmer's interface.
  48.         Besides its command interface, EditKeys provides for interfacing to some text editor.  Currently, EditKeys is
  49.         integrated into the editors Ed and ET.
  50.     PROCEDURE GetHandler;
  51.         To be called via Oberon.Call, this procedure allows run-time binding of EditKeys to an editor.  Thus the
  52.         editor is usable even if the EditKeys module is not available.  In order to bind EditKeys to some editor
  53.         procede as follows:
  54.             MODULE Editor;
  55.                 IMPORT
  56.                     Oberon;
  57.                 VAR
  58.                     macroHandler: Display.Handler;
  59.                 PROCEDURE* Handler(F: Display.Frame; VAR msg: Display.FrameMsg);    (*editor specific handler*)
  60.                 BEGIN
  61.                     IF macroHandler # NIL THEN macroHandler(F, msg) END;    (*must be first*)
  62.                     ...
  63.                 END Handler;
  64.                 PROCEDURE InstallMacros;
  65.                     CONST Magic = -42;
  66.                     VAR save: Oberon.ParList; res: INTEGER; name: ARRAY 32 OF CHAR;
  67.                 BEGIN save := Oberon.Par;
  68.                     NEW(Oberon.Par); NEW(Oberon.Par.frame); Oberon.Par.frame.X := 0; Oberon.Par.frame.Y := 0;
  69.                     Oberon.Par.pos := Magic;
  70.                     name := "EditKeys.GetHandler"; Oberon.Call(name, Oberon.Par, FALSE, res);
  71.                     IF res = 0 THEN macroHandler := Oberon.Par.frame.handle ELSE macroHandler := NIL END;
  72.                     Oberon.Par := save
  73.                 END InstallMacros;
  74.             BEGIN InstallMacros
  75.             END Editor;
  76.         The EditKeys handler consumes some Oberon.InputMsg messages with id = Oberon.consume by setting id to -1.
  77.         All other messages are either ignored or merely inspected.  It is expected that the frame passed to the EditKeys
  78.         handler is either a TextFrames.Frame or an extension thereof.  A macro expansion leads to direct manipulation
  79.         of the text attached to the frame (text inserts and deletions).
  80. The relevant section from Ed looks like:
  81.     PROCEDURE GetMacroHandle(VAR Handle: Display.Handler);
  82.         VAR cmd: ARRAY 32 OF CHAR; save, par: Oberon.ParList; res: INTEGER;
  83.     BEGIN
  84.         save := Oberon.Par;
  85.         NEW(par); NEW(par.frame); par.frame.X := 0; par.frame.Y := 0; par.pos := -42; (* magic *)
  86.         cmd := "EditKeys.GetHandler"; Oberon.Call(cmd, par, FALSE, res);
  87.         IF res = 0 THEN Handle := Oberon.Par.frame.handle
  88.         ELSE Handle := NIL; Modules.res := 0
  89.         END;
  90.         Oberon.Par := save
  91.     END GetMacroHandle;
  92.     PROCEDURE Handle*(F: Display.Frame; VAR msg: Display.FrameMsg);
  93.     BEGIN
  94.         IF MHandle # NIL THEN MHandle(F, msg) END;    (* Handle Macro *)
  95.         WITH F: TextFrames.Frame DO
  96.             ...
  97.